package com.binyouwei.calculator.widget

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.binyouwei.calculator.R

/**
 * @author 宾有为
 * @date 2025/3/21 17:26
 * @link https://blog.csdn.net/baidu_41616022?type=blog
 * @describe：
 **/
@Composable
fun MyButton(
    text: String,
    enabled: Boolean = true,
    modifier: Modifier = Modifier,
    fontSize: TextUnit = 14.sp,
    onConfirmClick: () -> Unit = {}
) {
    Button(
        onClick = { onConfirmClick() },
        enabled = enabled,
        modifier = modifier, // 设置按钮宽度
        colors = ButtonDefaults.buttonColors(
            containerColor = if (enabled) Color(0xFF467CE2) else Color(0x26000000), // 可点击时的背景颜色
        )
    ) {
        Text(
            text,
            color = Color(0xFFFFFFFF),
            fontSize = fontSize,
            modifier = Modifier.align(Alignment.CenterVertically)
        )
    }
}

@Composable
fun RoundButton(text: String, onClick: () -> Unit, fontColor: Color = colorResource(R.color.font_gray), modifier: Modifier = Modifier) {
    Column(modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally) {
        Button(onClick = { onClick.invoke() }, modifier = Modifier
            .size(80.dp)
            .shadow(elevation = 3.dp, shape = CircleShape, clip = true),
            colors = ButtonDefaults.buttonColors(
                containerColor = Color.White,
                contentColor = colorResource(id = R.color.font_gray)
            ),
            shape = CircleShape
        ) {
            Text(text = text, fontSize = 18.sp, color = fontColor)
        }
    }
}

@Composable
fun OvalVerticalButton(text: String, onClick: () -> Unit, fontColor: Color = colorResource(R.color.font_gray), cModifier: Modifier = Modifier, bModifier: Modifier = Modifier) {
    Column(modifier = cModifier, horizontalAlignment = Alignment.CenterHorizontally) {
        Button(onClick = { onClick.invoke() }, modifier = bModifier
            .fillMaxHeight()
            .shadow(elevation = 3.dp, shape = RoundedCornerShape(30), clip = true),
            colors = ButtonDefaults.buttonColors(
                containerColor = Color.White,
                contentColor = colorResource(id = R.color.font_gray)
            ),
            shape = RoundedCornerShape(30)
        ) {
           Text(text, fontSize = 18.sp, color = fontColor)
        }
    }
}